$(() => {
    getUserInfo()
    $('#exit').on('click', function () {
        let layer = layui.layer
        layer.confirm('是否退出登录', { icon: 3, title: '提示' }, function (index) {
            sessionStorage.removeItem('token')
            location.href = '../home/login.html'
            layer.close(index)
        })

    })
})
function getUserInfo() {
    let data = {
        token: sessionStorage.getItem('token')
    }
    $.ajax({
        type: 'POST',
        url: '/users/login/check',
        data,
        success: function (res) {
            console.log(res.status);
            if (res.status === 400 && res.msg == '当前登录失败，token失效了！') {
                sessionStorage.removeItem('token')
                location.href = '../home/login.html'
            } else if (res.status === 200) {
                let data = res.data
                console.log(data);
                $('.welcome').html(`欢迎您  ${res.data[0].nickname}`)
                setHeadPic(res)
            }
        }
    })
}